Tutorial 2: Reviewing the results of a generative design process
This tutorial is going to discuss how the resultant simulation file, a dill file with the file extension “aj1”, can be interpreted using the predefined tools in the mango generative design package.
Reading in the results file
First we must use dill to load in a file and investigate what types of output can be visualized to gauge the performance of the optimizer during the generative design process. We can also begin to view and export DNA origami design files in an automated fashion.
# Read in the output from tutorial1 and show some stuff
import dill
optimization_results = './output_folder/my_first_generated_design.aj1'
with open(optimization_results, 'rb') as f:
data = dill.load(f)
# Below are some sample fields of what the data object can store
print(data.temperature_values)
print('')
print(data.sim_time_seconds)
print('')
print(data.objectives_during_annealing)
[1.72514, 0.86257, 0.45971639947711174, 0.22985819973855587, 0.15102181797547176, 0.10654847922334919, 0.0879666973399053, 0.06552367707742573, 0.03276183853871287, 0.016380919269356434]
145.9877655506134
[17.202, 17.168, 15.769, 17.168, 15.961, 15.959, 15.978, 15.955, 15.982, 16.006, 16.032, 17.251, 19.118, 17.399, 15.964, 14.747, 14.745, 15.961, 17.399, 15.964, 17.399, 19.118, 17.633, 17.649, 16.228, 16.24, 16.255, 16.271, 16.272, 15.183, 15.162, 14.344, 14.354, 13.682, 13.684, 13.679, 13.666, 13.679, 13.678, 13.674, 13.684, 13.682, 13.678, 13.676, 13.659, 13.644, 13.09, 13.083, 13.092, 13.097, 13.129, 13.667, 13.664, 13.663, 13.674, 13.684, 13.673, 13.676, 13.667, 13.674, 13.678, 13.705, 13.699, 12.827, 12.848, 12.844, 13.717, 13.738, 13.738, 13.737, 13.735, 13.738, 13.729, 13.725, 12.816, 12.817, 12.824, 12.825, 12.82, 12.824, 12.826, 12.835, 12.833, 12.852, 12.052, 12.047, 12.847, 12.848, 12.839, 12.04, 12.038, 12.027, 12.025, 12.017, 12.011, 12.015, 12.016, 12.024, 12.026, 12.031, 12.044, 12.036, 12.04, 12.041, 12.84, 12.847, 12.858, 12.859, 12.86, 12.152, 12.151, 12.143, 12.851, 12.846, 12.858, 12.871, 12.232, 12.231, 12.231, 12.242, 12.235, 12.255, 12.247, 12.239, 12.241, 12.251, 12.236, 12.22, 12.221, 12.217, 12.216, 12.219, 12.217, 12.218, 12.217, 11.491, 11.489, 11.484, 11.489, 11.479, 11.478, 11.488, 11.474, 11.473, 11.475, 11.478, 11.479, 11.485, 11.081, 11.081, 11.082, 11.082, 11.097, 11.093, 11.1, 11.086, 11.082, 11.086, 11.077, 11.079, 11.061, 11.059, 11.062, 11.063, 11.053, 11.05, 11.05, 11.045, 11.045, 11.044, 11.043, 10.649, 10.65, 10.629, 10.616, 10.616, 10.617, 10.643, 10.645, 10.639, 10.656, 10.656, 10.668, 10.668, 10.657, 10.648, 10.631, 10.632, 10.631, 10.645, 10.638, 10.62, 10.632, 10.612, 10.611, 10.61, 10.609, 10.61, 10.611, 10.61, 10.609, 10.584, 10.581, 10.586, 10.601, 10.589, 10.578, 10.575, 10.591, 10.583, 10.586, 10.591, 10.588, 10.572, 10.584, 10.586, 10.568, 10.568, 10.567, 10.565, 10.568, 10.574, 10.57, 10.574, 10.592, 10.592, 10.592, 10.561, 10.557, 10.529, 10.539, 10.539, 10.529]
Viewing optimizer performance
While being able to access simple attributes is interesting, the mango framework also comes with some standardized functions to allow for easy output of figures. Generally, all figures created in this package utilize plotly.
Before investigating the actual generated designs, we may first want to consider what the objective function valuation looked like during the optimization process. This can inform us if our optimization-driven process “worked” or if essentially a random design was generated due to a lack of search space constraints or potentially the objective function being poorly defined (i.e., nothing to minimize).
Since simulated annealing was used in Tutorial 1, we will also want to look at the Temperature curve. We should see the temperature flatten over time to indicate that the optimization process slowly transitioned from a high energy (high T) state to a low energy, optimized (low T) state. However, as a reminder, the results from Tutorial run are a very “brief” search and this is really meant to just show how the results can be interpreted in one way.
from mango.visualizations.optimizer_analysis import ShapeAnneal_Analysis
# Simply pass in the aj1 filepath and you can plot figures out:
sa_output = ShapeAnneal_Analysis(results_path=optimization_results)
sa_output.plot_objective_trace()
sa_output.show_fig()
sa_output.plot_temperature_trace()
sa_output.show_fig()
Visualizing design output
Other than optimizer performance we can also view our final, optimized design (as this was a single objective problem, only one solution is generated). However, as the design evolution is stored, we can also use the mango package to create some other quick and easy visualizations for a user to interact with and learn more about how their generated design came to be.
To start, we can look at the final design using a cylindrical representation, where the cylinder in the design is approximately representative of a bundle of DNA.
from mango.visualizations.display_mesh_design import CylindricalRepresentation
ds = data.design_space
generated_design = CylindricalRepresentation(design=ds, bounding_box=ds.bounding_box)
generated_design.show_figure()
Other than just checking the final design in the output, we can select various designs from the design evolution. Here, the shape annealing optimization code saves out the design at the start of each epoch, and I will visualize a sample design below
tracked_designs = data.design_evolution
# The keys are the epochs, the values are the design_space attribute:
print(tracked_designs.keys())
dict_keys([0, 26, 52, 78, 104, 130, 156, 182, 208, 233])
objective_value, intermediary_design = tracked_designs[130]
# Use this design to create a cylinder rep and show:
generated_intermediary_design = CylindricalRepresentation(design=intermediary_design, bounding_box=intermediary_design.bounding_box)
generated_intermediary_design.show_figure()
Exporting a design to a DNA origami design
While the output of this framework is a .ply file, I have included scripts which can automatically export a design if you just provide a path for an automated scaffold routing algorithm. I removed the paths here and did not run this cell, but this is how you would go about exporting a design using tools built into the framework.
Note: the automated_scaffold_executable_path does NOT need to be a literal .exe file, it can be the mac or linux version of DAEDALUS / TALOS for example.
from mango.utils.design_io import export_DNA_design
automated_algorithm_path = "" # Example being DAEDALUS2, TALOS
scaffold_sequence_path = "" # If a custom sequence is being used for the scaffold, pass in the txt file filepath here
export_DNA_design(automated_scaffold_executable_path=automated_algorithm_path,
design=ds,
export_path='./output_folder',
savename_no_extension='my_generated_dna_design',
scaffold_sequence_filepath=scaffold_sequnce_path
)